
#include "TablePyrolysisGasADMaterial.h"

registerMooseObject("TrilobitaApp", TablePyrolysisGasADMaterial);

InputParameters
TablePyrolysisGasADMaterial::validParams()
{
    auto params = ADMaterial::validParams();

    params.addRequiredCoupledVar("temperature", "Coupled temperature");
    params.addRequiredCoupledVar("porepressure", "Coupled porepressure");
    params.addRequiredParam<std::vector<Real> >("rhog_list", "The vector of pyrolysis gas viscosity values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("rhogT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas viscosity");
    params.addRequiredParam<std::vector<Real> >("hg_list", "The vector of pyrolysis gas enthalpy values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("hgT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas enthalpy");
    params.addRequiredParam<std::vector<Real> >("viscosity_list", "The vector of pyrolysis gas viscosity values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("viscosityT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas viscosity");
    params.addRequiredParam<std::vector<Real> >("hg_list", "The vector of pyrolysis gas enthalpy values for building the piecewise function");
    params.addRequiredParam<std::vector<Real> >("hgT_list", "The vector of temperature values for building the piecewise function to compute pyrolysis gas enthalpy");
    return params;
}

TablePyrolysisGasADMaterial::TablePyrolysisGasADMaterial(const InputParameters& parameters)
    : ADMaterial(parameters),
    _temperature(coupledValue("temperature")),
    _porepressure(coupledValue("porepressure")),
    _rhog(declareADProperty<Real>("pyrolysis_gas_density")),
    _viscosity(declareADProperty<Real>("pyrolysis_gas_viscosity")),
    _gas_enthalpy(declareADProperty<Real>("pyrolysis_gas_enthalpy"))

{
    _rhog_list = getParam<std::vector<Real>>("rhog_list");
    _rhogT_list = getParam<std::vector<Real>>("rhogT_list");
    _func_rhog_T = LinearInterpolation(_rhogT_list, _rhog_list);
    _viscosity_list = getParam<std::vector<Real>>("viscosity_list");
    _viscosityT_list = getParam<std::vector<Real>>("viscosityT_list");
    _func_viscosity_T = LinearInterpolation(_viscosityT_list, _viscosity_list);
    _hg_list = getParam<std::vector<Real>>("hg_list");
    _hgT_list = getParam<std::vector<Real>>("hgT_list");
    _func_hg_T = LinearInterpolation(_hgT_list, _hg_list);
}

void
TablePyrolysisGasADMaterial::initQpStatefulProperties()
{
   _rhog[_qp] = _func_rhog_T.sample(_temperature[_qp]);
    _viscosity[_qp] = _func_viscosity_T.sample(_temperature[_qp]);
    _gas_enthalpy[_qp] = _func_hg_T.sample(_temperature[_qp]);

}


void
TablePyrolysisGasADMaterial::computeQpProperties()
{
    _rhog[_qp] = _func_rhog_T.sample(_temperature[_qp]);
    _viscosity[_qp] = _func_viscosity_T.sample(_temperature[_qp]);
    _gas_enthalpy[_qp] = _func_hg_T.sample(_temperature[_qp]);
}